package com.ymatou.iapi.payment.testcase;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.payment.parameter.AcquireOrderBean;
import com.ymatou.iapi.payment.parameter.CheckPaymentBean;
import com.ymatou.iapi.payment.parameter.QueryBaofu;
import com.ymatou.iapi.payment.service.AutoPaymentCheckCall;
import com.ymatou.iapi.payment.service.CheckApplepayPaymentCall;
import com.ymatou.iapi.payment.service.CheckPaymentCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.database.model.MPayment;
import com.ymttest.database.sqlwapper.PayGateWayWapper;
import com.ymttest.utils.BaofooSignature;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

/**
 * 支付对账接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_CheckPayment {
	private static CheckPaymentBean checkpaymentBean;
	private static CheckPaymentCall checkpaymentCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("支付对账接口");
	}

	@Before
	public void caseUp() {
		checkpaymentBean = new CheckPaymentBean();
		checkpaymentCall = new CheckPaymentCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(checkpaymentCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_001() {
		Logger.start(true, "10支付宝PC未支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("10");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//10");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(2, ppm.getCheckStatus(), "验证CheckStatus");
			Logger.verifyEquals(1, ppm.getPayStatus(), "验证PayStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_002() {
		Logger.start(true, "10支付宝PC已支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("10");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//10");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_003() {
		Logger.start(false, "10支付宝PC未支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("10");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//10");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			m.put("MockResult-AliPay-is_success", "N");
			m.put("MockResult-AliPay-error", "TRADE_NOT_EXIST");
			m.put("MockResult-AliPay-trade_status", "TRADE_NOT_EXIST");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_004() {
		Logger.start(false, "10支付宝PC已支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("10");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//10");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			m.put("MockResult-AliPay-is_success", "N");
			m.put("MockResult-AliPay-error", "TRADE_NOT_EXIST");
			m.put("MockResult-AliPay-trade_status", "TRADE_NOT_EXIST");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-20, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_005() {
		Logger.start(false, "10支付宝PC未支付最终对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("10");
			PayGateWayCallService.acquireOrder(aqb);
			// PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//10");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(true);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			m.put("MockResult-AliPay-is_success", "N");
			m.put("MockResult-AliPay-error", "TRADE_NOT_EXIST");
			m.put("MockResult-AliPay-trade_status", "TRADE_NOT_EXIST");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-10, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_006() {
		Logger.start(true, "13支付宝-APP未支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("13");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//13");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(2, ppm.getCheckStatus(), "验证CheckStatus");
			Logger.verifyEquals(1, ppm.getPayStatus(), "验证PayStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_007() {
		Logger.start(true, "13支付宝-APP已支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("13");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//13");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_008() {
		Logger.start(false, "13支付宝-APP未支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("13");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//13");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			m.put("MockResult-AliPay-is_success", "N");
			m.put("MockResult-AliPay-error", "TRADE_NOT_EXIST");
			m.put("MockResult-AliPay-trade_status", "TRADE_NOT_EXIST");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_009() {
		Logger.start(false, "13支付宝-APP已支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("13");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//13");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			m.put("MockResult-AliPay-is_success", "N");
			m.put("MockResult-AliPay-error", "TRADE_NOT_EXIST");
			m.put("MockResult-AliPay-trade_status", "TRADE_NOT_EXIST");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-20, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_010() {
		Logger.start(false, "13支付宝-APP未支付最终对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("13");
			PayGateWayCallService.acquireOrder(aqb);
			// PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//13");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(true);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			m.put("MockResult-AliPay-is_success", "N");
			m.put("MockResult-AliPay-error", "TRADE_NOT_EXIST");
			m.put("MockResult-AliPay-trade_status", "TRADE_NOT_EXIST");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-10, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_011() {
		Logger.start(true, "14微信-JSAPI未支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("14");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//14");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(2, ppm.getCheckStatus(), "验证CheckStatus");
			Logger.verifyEquals(1, ppm.getPayStatus(), "验证PayStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_012() {
		Logger.start(true, "14微信-JSAPI已支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("14");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//14");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_013() {
		Logger.start(false, "14微信-JSAPI未支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("14");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//14");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			m.put("MockResult-WeiXin-return_code", "FAIL");
			m.put("MockResult-WeiXin-result_code", "FAIL");
			m.put("MockResult-WeiXin-trade_state", "NOTPAY");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_014() {
		Logger.start(false, "14微信-JSAPI已支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("14");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//14");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			m.put("MockResult-WeiXin-return_code", "FAIL");
			m.put("MockResult-WeiXin-result_code", "FAIL");
			m.put("MockResult-WeiXin-trade_state", "NOTPAY");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-20, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_015() {
		Logger.start(false, "14微信-JSAPI未支付最终对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("14");
			PayGateWayCallService.acquireOrder(aqb);
			// PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//14");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(true);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			m.put("MockResult-WeiXin-return_code", "FAIL");
			m.put("MockResult-WeiXin-result_code", "FAIL");
			m.put("MockResult-WeiXin-trade_state", "NOTPAY");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-10, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_016() {
		Logger.start(true, "15微信APP未支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("15");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//15");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(2, ppm.getCheckStatus(), "验证CheckStatus");
			Logger.verifyEquals(1, ppm.getPayStatus(), "验证PayStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_017() {
		Logger.start(true, "15微信APP已支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("15");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//15");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_018() {
		Logger.start(false, "15微信APP未支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("15");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//15");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			m.put("MockResult-WeiXin-return_code", "FAIL");
			m.put("MockResult-WeiXin-result_code", "FAIL");
			m.put("MockResult-WeiXin-trade_state", "NOTPAY");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_019() {
		Logger.start(false, "15微信APP已支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("15");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//15");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			m.put("MockResult-WeiXin-return_code", "FAIL");
			m.put("MockResult-WeiXin-result_code", "FAIL");
			m.put("MockResult-WeiXin-trade_state", "NOTPAY");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-20, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_020() {
		Logger.start(false, "15微信APP未支付最终对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("15");
			PayGateWayCallService.acquireOrder(aqb);
			// PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//15");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(true);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			m.put("MockResult-WeiXin-return_code", "FAIL");
			m.put("MockResult-WeiXin-result_code", "FAIL");
			m.put("MockResult-WeiXin-trade_state", "NOTPAY");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-10, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_021() {
		Logger.start(true, "50招行未支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("50");
			PayGateWayCallService.acquireOrder(aqb);
			// PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//50");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getCMBMap(aqb.getPayPrice());
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(2, ppm.getCheckStatus(), "验证CheckStatus");
			Logger.verifyEquals(1, ppm.getPayStatus(), "验证PayStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_022() {
		Logger.start(true, "50招行已支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("50");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//50");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getCMBMap(aqb.getPayPrice());
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_023() {
		Logger.start(true, "50招行未支付实时对账failed,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("50");
			PayGateWayCallService.acquireOrder(aqb);
			// PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//50");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getCMBMap(aqb.getPayPrice());
			m.put("MockResult-Cmb-rspCode", "Failed");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-1, ppm.getCheckStatus(), "验证CheckStatus");
			Logger.verifyEquals(0, ppm.getPayStatus(), "验证PayStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_024() {
		Logger.start(true, "50招行已支付实时对账failed,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("50");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//50");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getCMBMap(aqb.getPayPrice());
			m.put("MockResult-Cmb-rspCode", "Failed");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-20, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_025() {
		Logger.start(true, "50招行未支付实时对账failed最终对账,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("50");
			PayGateWayCallService.acquireOrder(aqb);
			// PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//50");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(true);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getCMBMap(aqb.getPayPrice());
			m.put("MockResult-Cmb-rspCode", "Failed");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-10, ppm.getCheckStatus(), "验证CheckStatus");
			Logger.verifyEquals(0, ppm.getPayStatus(), "验证PayStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_026() {
		Logger.start(true, "50招行已支付实时对账MSS3206,验证checkstatus为unknown状态不变,JIRACONN-5757");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("50");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//50");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getCMBMap(aqb.getPayPrice());
			m.put("MockResult-Cmb-rspCode", "MSS3206");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_027() {
		Logger.start(true, "60ApplePay未支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("60");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAppleMockMap("00", Integer.valueOf(aqb.getPayPrice() + "00"), trandno);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(2, ppm.getCheckStatus(), "验证CheckStatus");
			Logger.verifyEquals(1, ppm.getPayStatus(), "验证PayStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_028() {
		Logger.start(true, "60applepay已支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("60");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAppleMockMap("00", Integer.valueOf(aqb.getPayPrice() + "00"), trandno);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, ppm.getCheckStatus(), "验证CheckStatus");

			List<Map> mocks = new PayGateWayWapper().selectMockHttpRecordByMockId(m.get("MockId").toString());
			Logger.debug("mocks:" + FormatUtil.beanToGSONString(mocks));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_029() {
		Logger.start(false, "60applepay未支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("60");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			// A6在对账时是失败
			Map m = getAppleMockMap("A6", Integer.valueOf(aqb.getPayPrice() + "00"), trandno);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-1, ppm.getCheckStatus(), "验证CheckStatus");

			List<Map> mocks = new PayGateWayWapper().selectMockHttpRecordByMockId(m.get("MockId").toString());
			Logger.debug("mocks:" + FormatUtil.beanToGSONString(mocks));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_030() {
		Logger.start(false, "60applepay已支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("60");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			// 36与原交易信息不符
			Map m = getAppleMockMap("36", Integer.valueOf(aqb.getPayPrice() + "00"), trandno);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-20, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_031() {
		Logger.start(false, "60applepay未支付最终对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("60");
			PayGateWayCallService.acquireOrder(aqb);
			// PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(true);
			checkpaymentCall.setData(checkpaymentBean);
			// 62交易失败，发卡银行不支持该商户，请更换其他银行卡
			Map m = getAppleMockMap("62", Integer.valueOf(aqb.getPayPrice() + "00"), trandno);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-10, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_032() {
		Logger.start(false, "60applepay已支付实时对账12重复交易,保持原状态");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("60");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			MPayment oldppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			checkpaymentBean.setPayType(aqb.getPayType());//60");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			// 12重复交易
			Map m = getAppleMockMap("12", Integer.valueOf(aqb.getPayPrice() + "00"), trandno);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(oldppm.getCheckStatus(), ppm.getCheckStatus(), "验证CheckStatus-code12不处理");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_033() {
		Logger.start(true, "AutoPaymentCheck对账");
		try {
			AutoPaymentCheckCall cpcall = new AutoPaymentCheckCall();
			cpcall.callService();
			// Logger.verifyEquals("ok", cpcall.getReturnData(), "验证返回结果");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	@Ignore
	// 手动确认
	public void Tc_CheckPayment_034() {
		Logger.start(true, "CheckApplepayPayment对账");
		try {
			CheckApplepayPaymentCall cpcall = new CheckApplepayPaymentCall();
			cpcall.callService();
			// Logger.verifyEquals("ok", cpcall.getReturnData(), "验证返回结果");
			// 数据库记录
			// select * from PP_PaymentCheck where PaymentChannel=60;
			//
			// SELECT * from PP_PaymentCheckDetail where PaymentCheckId=??
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_035() {
		Logger.start(true, "70宝付未支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("70");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);

			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.debug("PayStatus:" + ppm.getPayStatus());

			checkpaymentBean.setPayType(aqb.getPayType());//70");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);

			QueryBaofu baofuq = initQueryBaofu(aqb, trandno);
			BaofooSignature bf = new BaofooSignature();
			String send = bf.encryptData(FormatUtil.beanToGSONString(baofuq));
			checkpaymentCall.addHeader("MockResult-BaofooPay-Result", send);
			checkpaymentCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			checkpaymentCall.addHeader("MockId", mockid);

			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);

			ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.debug("PayStatus:" + ppm.getPayStatus());
			Logger.verifyEquals(2, ppm.getCheckStatus(), "验证CheckStatus");
			Logger.verifyEquals(1, ppm.getPayStatus(), "验证PayStatus");
			Logger.verifyEquals(baofuq.getOrder_id(), ppm.getInstitutionPaymentId(), "验证InstitutionPaymentId");
//			Logger.verifyEquals(baofuq.getVoucher_no(), ppm.getBankId(), "验证BankId");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_036() {
		Logger.start(true, "70宝付已支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("70");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//70");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);

			QueryBaofu baofuq = initQueryBaofu(aqb, trandno);
			BaofooSignature bf = new BaofooSignature();
			String send = bf.encryptData(FormatUtil.beanToGSONString(baofuq));
			checkpaymentCall.addHeader("MockResult-BaofooPay-Result", send);
			checkpaymentCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			checkpaymentCall.addHeader("MockId", mockid);

			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, ppm.getCheckStatus(), "验证CheckStatus");

			List<Map> mocks = new PayGateWayWapper().selectMockHttpRecordByMockId(mockid);
			Logger.debug("mocks:" + FormatUtil.beanToGSONString(mocks));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_037() {
		Logger.start(false, "70宝付未支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("70");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//70");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			QueryBaofu baofuq = initQueryBaofu(aqb, trandno);
			baofuq.setResp_code("0001");
			baofuq.setResp_msg("订单交易失败");
			BaofooSignature bf = new BaofooSignature();
			String send = bf.encryptData(FormatUtil.beanToGSONString(baofuq));
			checkpaymentCall.addHeader("MockResult-BaofooPay-Result", send);
			checkpaymentCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			checkpaymentCall.addHeader("MockId", mockid);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-1, ppm.getCheckStatus(), "验证CheckStatus");

			List<Map> mocks = new PayGateWayWapper().selectMockHttpRecordByMockId(mockid);
			Logger.debug("mocks:" + FormatUtil.beanToGSONString(mocks));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_038() {
		Logger.start(false, "70宝付未支付最终对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("70");
			PayGateWayCallService.acquireOrder(aqb);
			// PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//70");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(true);
			checkpaymentCall.setData(checkpaymentBean);
			QueryBaofu baofuq = initQueryBaofu(aqb, trandno);
			baofuq.setResp_code("0001");
			baofuq.setResp_msg("订单交易失败");
			BaofooSignature bf = new BaofooSignature();
			String send = bf.encryptData(FormatUtil.beanToGSONString(baofuq));
			checkpaymentCall.addHeader("MockResult-BaofooPay-Result", send);
			checkpaymentCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			checkpaymentCall.addHeader("MockId", mockid);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-10, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_039() {
		Logger.start(false, "70宝付已支付实时对账重复交易,保持原状态");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("70");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//70");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			// 12重复交易
			QueryBaofu baofuq = initQueryBaofu(aqb, trandno);
			baofuq.setResp_code("0009");
			baofuq.setResp_msg("重复交易");
			BaofooSignature bf = new BaofooSignature();
			String send = bf.encryptData(FormatUtil.beanToGSONString(baofuq));
			checkpaymentCall.addHeader("MockResult-BaofooPay-Result", send);
			checkpaymentCall.addHeader("Mock", "1");
			String mockid = TestDataManager.getRandomUUID().toString();
			checkpaymentCall.addHeader("MockId", mockid);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(0, ppm.getCheckStatus(), "验证CheckStatus-code12不处理");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_040() {
		Logger.start(true, "50招行已支付实时对账success对账金额不正确,验证checkstatus失败");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("50");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//50");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getCMBMap(aqb.getPayPrice()+0);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-15, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_041() {
		Logger.start(true, "60applepay已支付实时对账金额不正确,验证checkstatus失败");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("60");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAppleMockMap("00", Integer.valueOf(aqb.getPayPrice() +1), trandno);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-15, ppm.getCheckStatus(), "验证CheckStatus");

			List<Map> mocks = new PayGateWayWapper().selectMockHttpRecordByMockId(m.get("MockId").toString());
			Logger.debug("mocks:" + FormatUtil.beanToGSONString(mocks));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_042() {
		Logger.start(true, "9.支付宝-花呗已支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("9");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_043() {
		Logger.start(false, "9支付宝--花呗未支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("9");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			m.put("MockResult-AliPay-is_success", "N");
			m.put("MockResult-AliPay-error", "TRADE_NOT_EXIST");
			m.put("MockResult-AliPay-trade_status", "TRADE_NOT_EXIST");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_044() {
		Logger.start(false, "9支付宝--花呗已支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("9");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			m.put("MockResult-AliPay-is_success", "N");
			m.put("MockResult-AliPay-error", "TRADE_NOT_EXIST");
			m.put("MockResult-AliPay-trade_status", "TRADE_NOT_EXIST");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-20, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_CheckPayment_045() {
		Logger.start(false, "9支付宝-花呗未支付最终对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("9");
			PayGateWayCallService.acquireOrder(aqb);
			// PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(true);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getAlipayMockMap(aqb);
			m.put("MockResult-AliPay-is_success", "N");
			m.put("MockResult-AliPay-error", "TRADE_NOT_EXIST");
			m.put("MockResult-AliPay-trade_status", "TRADE_NOT_EXIST");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-10, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_046() {
		Logger.start(true, "17微信app小程序未支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("17");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//14");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(2, ppm.getCheckStatus(), "验证CheckStatus");
			Logger.verifyEquals(1, ppm.getPayStatus(), "验证PayStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_047() {
		Logger.start(true, "17微信app小程序已支付实时对账success,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("17");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//14");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_048() {
		Logger.start(false, "17微信app小程序未支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("17");
			PayGateWayCallService.acquireOrder(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//14");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			m.put("MockResult-WeiXin-return_code", "FAIL");
			m.put("MockResult-WeiXin-result_code", "FAIL");
			m.put("MockResult-WeiXin-trade_state", "NOTPAY");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-1, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_CheckPayment_049() {
		Logger.start(false, "17微信app小程序已支付实时对账fail,验证checkstatus成功");
		try {
			AcquireOrderBean aqb = PayGateWayCallService.initAcquireOrder("17");
			PayGateWayCallService.acquireOrder(aqb);
			PayGateWayCallService.notifyCall(aqb);
			String trandno = getPaymentId(aqb);
			checkpaymentBean.setPayType(aqb.getPayType());//14");
			checkpaymentBean.setPaymentId(trandno);
			checkpaymentBean.setFinalCheck(false);
			checkpaymentCall.setData(checkpaymentBean);
			Map m = getWeiXinMockMap(aqb);
			m.put("MockResult-WeiXin-return_code", "FAIL");
			m.put("MockResult-WeiXin-result_code", "FAIL");
			m.put("MockResult-WeiXin-trade_state", "NOTPAY");
			addMock(checkpaymentCall, m);
			checkpaymentCall.callService();
			Logger.verifyEquals("ok", checkpaymentCall.getReturnData(), "验证返回结果");
			Thread.sleep(2000);
			MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
			Logger.verifyEquals(-20, ppm.getCheckStatus(), "验证CheckStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	private QueryBaofu initQueryBaofu(AcquireOrderBean aqb, String trandno) {
		QueryBaofu qbf = new QueryBaofu();
		Integer price = new BigDecimal(aqb.getPayPrice()).multiply(new BigDecimal(100)).intValue();
		qbf.setSucc_amt(price.toString());
		qbf.setResp_code("0000");
		qbf.setResp_msg("成功");
		qbf.setTrans_id(trandno);
		
		qbf.setData_type("json");
		qbf.setMember_id(PayGateWayCallService.BaoFu_MERID);
		qbf.setTerminal_id(PayGateWayCallService.BaoFu_TerminalID);
		qbf.setTrade_date(YMTDateUtil.getSysTime("yyyyMMddHHmmss"));
		qbf.setTxn_sub_type("08");
		qbf.setTxn_type("20199");
		qbf.setOrder_id(TestDataManager.getRandomUUID().toString());
		qbf.setVoucher_no(TestDataManager.getRandomUUID().toString().replaceAll("-", ""));
		return qbf;
	}

	private Map getWeiXinMockMap(AcquireOrderBean aqb) throws Exception {
		Logger.comment("获取默认的WeiXinMock信息");
		Map m = new HashMap<String, String>();
		m.put("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		m.put("MockId", mockid);
		m.put("MockResult-WeiXin-return_code", "SUCCESS");
		m.put("MockResult-WeiXin-result_code", "SUCCESS");
		m.put("MockResult-WeiXin-trade_state", "SUCCESS");
		MPayment ppm = PayGateWayCallService.getPPayment(aqb);
		m.put("MockResult-WeiXin-total_fee", new BigDecimal(aqb.getPayPrice()).multiply(BigDecimal.valueOf(100)).setScale(0).toString());
		m.put("MockResult-WeiXin-refund_fee", new BigDecimal(aqb.getPayPrice()).multiply(BigDecimal.valueOf(100)).setScale(0).toString());
		m.put("MockResult-WeiXin-out_trade_no",ppm.getPaymentId());
		
		return m;
	}

	private Map getCMBMap(String payprice) {
		Logger.comment("获取默认的CMBMock信息");
		Map m = new HashMap<String, String>();
		m.put("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		m.put("MockId", mockid);
		m.put("MockResult-Cmb-rspCode", "SUC0000");
		m.put("MockResult-Cmb-cardType", "02");
		m.put("MockResult-Cmb-orderAmount", payprice);
		m.put("MockResult-Cmb-discountAmount", "0.00");
		m.put("MockResult-Cmb-orderStatus", "0");
		m.put("MockResult-Cmb-date", YMTDateUtil.getSysTime("yyyyMMdd"));
		return m;
	}

	/**
	 * 获取默认的AlipayMock信息
	 * 
	 * @return
	 */
	private Map getAlipayMockMap(AcquireOrderBean aqb) {
		Logger.comment("获取默认的AlipayMock信息");
		Map m = new HashMap<String, String>();
		m.put("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		m.put("MockId", mockid);
		m.put("MockResult-AliPay-is_success", "T");
		m.put("MockResult-AliPay-error", "OK");
		m.put("MockResult-AliPay-trade_status", "TRADE_SUCCESS");
		m.put("MockResult-AliPay-total_fee",new BigDecimal(aqb.getPayPrice()).setScale(2).toString());
		return m;
	}

	/**
	 * ApplepayMock
	 * 
	 * @param paice
	 *            金额 单位分
	 * @param orderid
	 *            订单号
	 * @param code
	 *            返回报文origRespCode
	 * @return
	 */
	private Map getAppleMockMap(String code, Integer paice, String orderid) {
		Logger.comment("获取默认的ApplepayMock信息");
		Map m = new HashMap<String, String>();
		m.put("Mock", "1");
		String mockid = TestDataManager.getRandomUUID().toString();
		m.put("MockId", mockid);
		m.put("MockResult-ApplePay-origRespCode", code);
		m.put("MockResult-ApplePay-settleAmt", paice);
		m.put("MockResult-ApplePay-orderId", orderid);
		m.put("MockResult-ApplePay-merId", PayGateWayCallService.APPLEPAY_MERID);
		return m;
	}

	private void addMock(CheckPaymentCall cpcall, Map m) {
		Logger.comment("初始化MockHeader信息:" + m.toString());
		Set sl = m.entrySet();
		for (Object o : sl) {
			String[] ss = o.toString().split("=");
			String value = FormatUtil.urlEncode(ss[1]);
			cpcall.addHeader(ss[0], value);
		}
	}

	/**
	 * 获取PaymentId
	 * 
	 * @param aqb
	 *            收单bean
	 * @return 对应的PaymentId
	 * @throws Exception
	 */
	private String getPaymentId(AcquireOrderBean aqb) throws Exception {
		MPayment ppm = new PayGateWayWapper().selectPaymentByTradingid(aqb.getOrderId()).get(0);
		String trandno = ppm.getPaymentId();
		return trandno;
	}

}